/*
 * GToe: Gtk+ TicTacToe
 * misc.c: miscellaneous
 *
 * Copyright (C) 2010 Dani Soufi <danisoufi@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "../include/core.h"
#include "../include/player.h"
#include "../include/misc.h"
#include "../include/info.h"

int
who_starts_first(void)
{
    int n;

    /* seed: RAND_MAX */
    srandom(time(0));

    n = random() % (9) + 1;

    if (n % 2 == 0)
    {
        return 2;
    }

    return 1;
}

void
print_info_screen(void)
{
     printf("\n     ------------- GToe -------------                    \n");
     printf("GToe is a classic TicTacToe game written for Linux and UNIX\n");
     printf("and released under GPL license. It is possible to play it  \n");
     printf("against the computer or another player on the same PC. That\n");
     printf("should be enough for you to have fun with (for now i hope).\n");
     printf("For a detailed guide on HOW TO PLAY and more infos type:   \n");
     printf("man gtoe                                                 \n\n");
     printf("GToe %s                                           \n", VERSION);
     printf("Copyright %s 2010 %s %s    \n", COPYRIGHT, AUTHOR, AUTHOR_MAIL);
     printf("%s                                               \n", HOMEPAGE);
}

void
parse_cmd_args(int argc, char *argv[])
{
     if (argc < 2)
     {
        return;
     }

     for (int i = 1; i <= argc -1; ++i)
     {
         if ((!strcmp(argv[i], "-h")) || (!strcmp(argv[i], "--help"))) {
             fprintf(stdout, "GToe %s                                   \n", VERSION);
             fprintf(stdout, "                                                   \n");
             fprintf(stdout, "usage: gtoe [OPTIONS]                              \n");
             fprintf(stdout, "                                                   \n");
             fprintf(stdout, "-h, --help        display this help and exit       \n");
             fprintf(stdout, "-v, --version     output version information       \n");
             fprintf(stdout, "GToe project is hosted at: %s            \n", HOMEPAGE);
             fprintf(stdout, "                                                   \n");
             fprintf(stdout, "Please send any bug reports, or comments to:       \n");
             fprintf(stdout, "%s %s                         \n", AUTHUR, AUTHOR_MAIL);

             exit(EXIT_SUCCESS);
         }
         else if ((!strcmp(argv[i], "-v")) || (!strcmp(argv[i], "--version")))
         {
             fprintf(stdout, "GToe %s                                           \n", VERSION);
             fprintf(stdout, "                                                           \n");
             fprintf(stdout, "Written by %s %s                      \n", AUTHUR, AUTHOR_MAIL);
             fprintf(stdout, "Copyright %s 2010 %s %s    \n", COPYRIGHT, AUTHOR, AUTHOR_MAIL);
             fprintf(stdout, "                                                           \n");
             fprintf(stdout, "This software is released under the GNU GPL.               \n");

             exit(EXIT_SUCCESS);
         }
         else
         {
             fprintf(stdout, "%s: unrecognized option `%s'\n", argv[0], argv[i]);
             fprintf(stdout, "Try `%s --help' for more information.\n", argv[0]);

             exit(EXIT_SUCCESS);
         }
     }

     return;
}
